<?php
$elem_id = str_replace('/','_',$view).'_save' ;
$routerBase = lcfirst(self::$console->argument('className')) ;
$fileds = '' ;
foreach($colmns as $col){
    if($col->Key != 'PRI'){
        $fileds .= "                {$col->Field}:'',\n";
    }
}


$validates = '' ;
foreach($colmns as $col){
    if($col->Key != 'PRI'){
        $validates .= "                {$col->Field}:[Va.required],\n";
    }
}

?>


<div id="<?=$elem_id?>">
    <form>
        <zrow>
<?php

$newColmns = array_filter($colmns,function($v){
    return $v->Key !== 'PRI' ;
});
$newColmns = array_values($newColmns) ;
foreach ($newColmns as $k => $col){
    echo <<<ROW

            <zcol :md="6">
                <zinput label="$col->Comment" name="{$col->Field}" :ctx="this"/>
            </zcol>

ROW;
    if($k % 2 == 1){
echo <<<ZOL
        </zrow>


        <zrow>
ZOL;

    }
}
?>
        </zrow>

        <a @click="submit" class="btn btn-primary">提交</a>
    </form>

</div>

<script>
    new Vue({
        el:'#<?=$elem_id?>',
        mounted:function(){
            if(this.editData){
                this.form = this.editData ;
            }
            this.state.status = 'mounted'
        },
        data:{
            state:{
                status:''
            },
            form:{
<?=$fileds?>
            },
            validate:{
<?=$validates?>
            },
            editData:{!! $data !!}
        },
        methods:{
            submit:function(){

                if(!validateAll(this)){
                    return
                }

                var id = App.url().param('id') || '' ;

                zhttp.post('<?=$routerBase?>/save?id='+id,this.form,function (d) {
                    if(d.code == 0){
                        success('操作成功')
                        //Loader.getDialog('<?=$routerBase?>/save').close()
                        go('<?=$routerBase?>/index')
                    }else{

                    }
                    return false ;
                })
            }
        }
    })
</script>